package za.org.jcicada.genss.sensor.impl;

import za.org.jcicada.genss.sensor.ISensorType;

/**
 * LRU sensor type which can take either value NOMINAL or ERROR.
 * @author apinska
 * @author rcrida
 */
public class TypeLRU implements ISensorType {
	private static final long serialVersionUID = 1L;
	
    /**
     * Singleton instance of TypeLRU
     */
    static private final TypeLRU instance = new TypeLRU();
    
    /**
     * Factory method used to access instance of TypeLRU
     * @return an instance of TypeLRU
     */
    static public TypeLRU getInstance() {
        return instance;
    }
    
    /**
     * Factory method used to access instance of TypeLRU
     * @param ignored
     * @return an instance of TypeLRU
     */
    static public TypeLRU getInstance(String[] args) {
        return instance;
    }
    
    /**
     * Define the values that the LRU sensor type may take.
     */
    public enum LRU {
        NOMINAL,
        ERROR
    }
    
    /**
     * Private constructor forces use of getInstance().
     */
    private TypeLRU() {
    }
    
    public boolean isValid(Object value) {
        return value instanceof LRU;
    }
    
    @Override
    public String toString() {
    	return "LRU";
    }

    @Override
    public boolean equals(Object aOther) {
        if (this == aOther) return true;
        return aOther instanceof TypeLRU;
    }
    
    @Override
    public int hashCode() {
        return 0;
    }

    public String[] toStringArray() {
        return new String[]{};
    }

    public Object valueOf(String string) {
        return LRU.valueOf(string.toUpperCase());
    }

    public double doubleValueOf(Object value) {
    	return ((LRU) value).ordinal();
    }
    
}
